
/***************************************************************************************************************************

This part of the dofile is copy-pasted from the dofile "Tables.do" from Burde and Linden (2013, AEJ Applied)
We made one change: The working directory was added.

***************************************************************************************************************************/

cd "$INDTA" 

use afghanistan_anonymized_data.dta, clear

*Outlier Identification;
gen nonoutlier = 1
replace nonoutlier = 0 if f07_num_ppl_hh_cnt > 20 & f07_observed == 1
replace nonoutlier = 0 if f07_jeribs_cnt > 10 & f07_observed == 1
replace nonoutlier = 0 if f07_num_sheep_cnt > 50 & f07_observed == 1
replace nonoutlier = 0 if s08_num_ppl_hh_cnt > 20 & s08_observed == 1
replace nonoutlier = 0 if s08_jeribs_cnt > 10 & s08_observed == 1
replace nonoutlier = 0 if s08_num_sheep_cnt > 50 & s08_observed == 1



/***************************************************************************************************************************

This part of the dofile is our code: Create Z, D, Y, and globals per application

***************************************************************************************************************************/

***Data prep for main analysis
gen z=treatment

gen d1=f07_formal_school
gen d2=s08_formal_school

gen y=s08_both_norma_total

gen noweight=1

global controls		chagcharan
global weight		noweight
global clustervar	clustercode

global controls_s12 chagcharan_s1 chagcharan_s2
			
***Data prep for analysis per x
assert 	chagcharan!=.
gen 	chagcharan_0=0, after(chagcharan)
replace chagcharan_0=1 if chagcharan==0
gen 	chagcharan_1=0, after(chagcharan)
replace chagcharan_1=1 if chagcharan==1

gen everyonex2=1
gen everyonex3=1

global controlsx1  	chagcharan_0 chagcharan_1
global controlsx2  	everyonex2
global controlsx3  	everyonex3

global clustervarx 	clustercode						
		
***Keep if vars are observed
keep if (f07_observed==1 & s08_observed==1 & s08_test_observed==1) & nonoutlier==1
		

		
/***************************************************************************************************************************
***Appendix: Replicate Table 4 (Panel A and B, column 1 3 5) of Burde and Linden (2013)
***Run before keep if vars==1 for exact results

forvalues g=1(-1)0 {
eststo: reg f07_formal_school treatment chagcharan if nonoutlier == 1 & f07_observed == 1 & f07_girl_cnt == `g', cluster(clustercode)
eststo: reg f07_both_norma_total treatment chagcharan if nonoutlier == 1 & f07_test_observed == 1 & f07_girl_cnt == `g', cluster(clustercode)
eststo: reg s08_both_norma_total treatment chagcharan if nonoutlier == 1 & s08_test_observed == 1 & s08_girls_cnt == `g', cluster(clustercode)
}

esttab, keep(treatment) b(3) se(3) nostar nonotes label title("Replication of Table 4 Burde and Linden (2013)")
eststo clear

***Replicate estimate of first stage upon d2 (and d1 for comparison)

forvalues g=1(-1)0 {
eststo: reg f07_formal_school treatment chagcharan if nonoutlier == 1 & f07_observed == 1 & f07_girl_cnt == `g', cluster(clustercode)
eststo: reg s08_formal_school treatment chagcharan if nonoutlier == 1 & s08_observed == 1 & f07_girl_cnt == `g', cluster(clustercode)
}

esttab, keep(treatment) b(3) se(3) nostar nonotes label title("Replication of Table 4 Burde and Linden (2013)")
eststo clear
***************************************************************************************************************************/

